package com.soriya.nestlive.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.soriya.nestlive.entity.LiveEntity;
import com.soriya.nestlive.entity.PageResult;
import com.soriya.nestlive.entity.VideoEntity;
import com.soriya.nestlive.entity.param.VideoListParam;
import com.soriya.nestlive.service.VideoService;
import com.soriya.nestlive.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/video")
public class VideoController {

    private final VideoService videoService;

    @Autowired
    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }

    @GetMapping("/{current}/{size}")
    public Result<?> list(@PathVariable Integer current, @PathVariable Integer size, VideoListParam param) {
        Page<VideoEntity> page = new Page<>(current, size);
        PageResult<VideoEntity> result = videoService.pageQuery(page, param);
        return Result.success(result);
    }

    @GetMapping("/{id}")
    public Result<VideoEntity> getById(@PathVariable Long id) {
        VideoEntity data = videoService.getById(id);
        return Result.success(data);
    }

    @PostMapping
    public Result<?> save(@RequestBody VideoEntity entity) {
        boolean save = videoService.save(entity);
        return Result.update(save);
    }

    @PutMapping
    public Result<?> updateById(@RequestBody VideoEntity entity) {
        boolean b = videoService.updateById(entity);
        return Result.update(b);
    }

    @DeleteMapping("/{id}")
    public Result<?> removeById(@PathVariable Long id) {
        boolean b = videoService.removeById(id);
        return Result.update(b);
    }

}
